package boundarys;

import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JButton;

import ccrm.BoundryControl;
import controllers.UserController;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.JLabel;

import entitys.Session;

import java.awt.Font;
import java.awt.Color;
import java.io.IOException;
import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;
import java.awt.Insets;

public class SGUI extends AbstractGUI{

	private JFrame frmCcrmS;
	private String userid;
	private String userpw;
	

	/**
	 * Create the application.
	 */
	public SGUI(String userid, String userpw) {
		this.userid = userid;
		this.userpw = userpw;
		initialize();
		initGUI(frmCcrmS);
		frmCcrmS.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		GridBagLayout gridBagLayout = new GridBagLayout();
		gridBagLayout.columnWidths = new int[]{274, 179, 187, 74, 0, 0};
		gridBagLayout.rowHeights = new int[]{50, 31, 60, 71, 45, 41, 32, 0};
		gridBagLayout.columnWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
		gridBagLayout.rowWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
		frmCcrmS.getContentPane().setLayout(gridBagLayout);
		
		JButton logOut = new JButton("Log Out");
		logOut.setForeground(Color.RED);
		logOut.setFont(new Font("Tahoma", Font.BOLD, 11));
		logOut.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if(BoundryControl.GUIArr.size()==getIndex()+1)
				{
					goBack();
					UserController.LogoutUser(getUserid(), getUserpw());
				}
			}
		});
		
		JButton AddressClientBtn = new JButton("Address Clients");
		AddressClientBtn.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				new AddressCustomerGUI();
			}
		});
		
		JLabel lblSalespersonPanel = new JLabel("Sales Person Panel");
		lblSalespersonPanel.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 15));
		GridBagConstraints gbc_lblSalespersonPanel = new GridBagConstraints();
		gbc_lblSalespersonPanel.fill = GridBagConstraints.BOTH;
		gbc_lblSalespersonPanel.insets = new Insets(0, 0, 5, 5);
		gbc_lblSalespersonPanel.gridx = 1;
		gbc_lblSalespersonPanel.gridy = 0;
		frmCcrmS.getContentPane().add(lblSalespersonPanel, gbc_lblSalespersonPanel);
		GridBagConstraints gbc_AddressClientBtn = new GridBagConstraints();
		gbc_AddressClientBtn.fill = GridBagConstraints.BOTH;
		gbc_AddressClientBtn.insets = new Insets(0, 0, 5, 5);
		gbc_AddressClientBtn.gridx = 1;
		gbc_AddressClientBtn.gridy = 3;
		frmCcrmS.getContentPane().add(AddressClientBtn, gbc_AddressClientBtn);
		GridBagConstraints gbc_logOut = new GridBagConstraints();
		gbc_logOut.fill = GridBagConstraints.BOTH;
		gbc_logOut.insets = new Insets(0, 0, 5, 5);
		gbc_logOut.gridx = 0;
		gbc_logOut.gridy = 5;
		frmCcrmS.getContentPane().add(logOut, gbc_logOut);
		frmCcrmS.setVisible(true);
	}

	public String getUserpw() {
		return userpw;
	}

	public void setUserpw(String userpw) {
		this.userpw = userpw;
	}

	public String getUserid() {
		return userid;
	}

	public void setUserid(String userid) {
		this.userid = userid;
	}

	/**
	 * Initialize the contents of the frame.
	 */
	private void initialize() {
		frmCcrmS = new JFrame();
		frmCcrmS.addWindowListener(new WindowAdapter() {
			@Override
			public void windowClosing(WindowEvent e) {
				UserController.LogoutUser(getUserid(), getUserpw());
			}
		});
		frmCcrmS.setResizable(false);
		frmCcrmS.setTitle("CCRM>Salesperson Management");
		frmCcrmS.setBounds(100, 100, 364, 300);
		frmCcrmS.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	}

	@Override
	public void getReply(Object r) {
		// TODO Auto-generated method stub
		

		
	}
}
